# *-* coding:utf8 *-*

import sys
from PyQt5.QtWidgets import QMainWindow ,QApplication,QMessageBox
from PyQt5.QtGui import QIcon

from base import Ui_MainWindow

## 登录界面
class MainWindow(QMainWindow):
    def __init__(self,parent=None,second_window=None):
        super(MainWindow,self).__init__(parent)
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.setWindowTitle("PyQt MainWindow例子")
        
        self.second_window = second_window
        # 建立槽函数
        self.connet_login_2_button()

        self.exit()
    # 给这玩意加控件
    def login(self):

        admin,password = self.accept_login_info()
        print("helloworld",admin,password)
        if self.check(admin,password):
            print("helloworld",admin,password)

            self.close()
            if self.second_window:
                print("second_window")
                self.second_window.show()
        else:
            QMessageBox(QMessageBox.Warning,"警告","用户名或密码不正确").exec_()
            self.clear()
    def accept_login_info(self):
        # 修改为控件输入
        admin = self.ui.edit_username.text()
        password = self.ui.edit_password.text()
        return admin,password
    def check(self,admin,password):
        if admin == "root" and int(password) -123 ==0:
            ## 在新窗口弹出
            print("login success")
            return 1
        else:
            print("login failed,please check your login info")
            return 0
    def close_information_window(self):
        pass
    
    ####################################
    def connet_login_2_button(self):
        self.ui.login_button.clicked.connect(self.login)
    def exit(self):
        self.ui.login_button_clear.clicked.connect(self.close)
    def connet_clear_2_button(self):
        self.ui.login_button_clear.clicked.connect(self.clear)
    def clear(self):
        self.ui.edit_username.clear()
        self.ui.edit_password.clear()
## 功能选择界面
class simulation_Window(QMainWindow):
    def __init__(self,parent=None):
        super(MainWindow,self).__init__(parent)
        self.resize(400,200)
        self.status = self.statusBar()
        self.status.showMessage("STATE BAR",5000)
        self.setWindowTitle("PyQt MainWindow例子")
    def button_load_robot(self):
        pass
    def button_check_robot(self):
        pass
    def button_change_robot_color(self):
        pass
    def button_change_robot_place(self):
        pass
    def button_robot_init(self):
        pass
    def choose_mode(self):
        keyword = [0,1,2]
        return keyword
    def button_using_expert_modemove(self):
        pass
    def pause(self):
        pass

class train_expert_window(QMainWindow):
    def __init__(self,parent=None):
        super(MainWindow,self).__init__(parent)
        self.resize(400,200)
        self.status = self.statusBar()
        self.status.showMessage("STATE BAR",5000)
        self.setWindowTitle("PyQt MainWindow例子")
    def load_train_information(self):
        pass
    def show_necessary_information_inmainwindow(self):
        pass


class show_expert_window(QMainWindow):
    def __init__(self,parent=None):
        super(MainWindow,self).__init__(parent)
        self.resize(400,200)
        self.status = self.statusBar()
        self.status.showMessage("STATE BAR",5000)
        self.setWindowTitle("PyQt MainWindow例子")
    def button_load_robot(self):
        pass
    def button_check_robot(self):
        pass
    def button_change_robot_color(self):
        pass
    def button_change_robot_place(self):
        pass
    def button_robot_init(self):
        pass
    def choose_mode(self):
        keyword = [0,1,2]
        return keyword   
if __name__ =="__main__":
    app = QApplication(sys.argv)
    # app.setWindowIcon(QIcon("./images/cartoon1.ico"))
    A = MainWindow()
    B = MainWindow(second_window=A)
    B.show()

    sys.exit(app.exec_())
